<?php
include('include/init.php');



$do_array = array('register','activate');
if (!in_array($_REQUEST['do'],$do_array))
{
    $_REQUEST['do'] = $do_array[0];
}



/*
 * Die eigentliche Registration
 */
if ($_REQUEST['do'] == 'register')
{
    $template_array = array('home','register','customfield','customfield_radio',
                            'customfield_checkbox','customfield_option','customfield_select',
                            'customfield_multiselect','customfield_text','customfield_textarea',
                            'customfield_password','redirect');
    $template = new Template($template_array);
    $core->clean(array('username','email','email2','password','password2'),'POST');
    if ($_POST['submit'])
    {
        $registererror = FALSE;
        if (!strlen($core->cleaned('username')))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_username',$language->get('registererror_username_missing'));
        }
        elseif (strlen($core->cleaned('username')) < $core->get('username_min') || strlen($core->cleaned('username')) > $core->get('username_max'))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_username',sprintf($language->get('registererror_username_length'),$core->get('username_min'),$core->get('username_max')));
        }
        else
        {
            $query = 'SELECT
      	                user.username AS username,
      	                user.email AS email
        	          FROM `'.TABLEPREFIX.'user` AS user
            	      WHERE user.username=:username
            	        OR user.email=:email
            	      LIMIT 0,1';
            $core->db->prepare($query);
            $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
            $core->db->bind('email',$core->cleaned('email'),Database::PARAM_STR);
            $core->db->execute();
            $array = $core->db->fetchAll();
            $core->db->free();
             
            if ($array['username'] == $core->cleaned('username'))
            {
                $registererror = TRUE;
                $template->set('register','lang_registererror_username',$language->get('registererror_username_unique'));
            }
             
            if ($array['email'] == $core->cleaned('email'))
            {
                $registererror = TRUE;
                $template->set('register','lang_registererror_email',$language->get('registererror_email_unique'));
            }
            else
            {
                $template->set('register','lang_registererror_username','');
            }
        }

        if (!strlen($core->cleaned('password')))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_password',$language->get('registererror_password_missing'));
        }
        elseif (strlen($core->cleaned('password')) < $core->get('password_min'))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_password',$language->get('registererror_password_length'));
        }
        elseif ($core->cleaned('password') != $core->cleaned('password2'))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_password2',$language->get('registererror_password_equal'));
        }
        else
        {
            $template->set('register','lang_registererror_password','');
            $template->set('register','lang_registererror_password2','');
        }

        if (!strlen($core->cleaned('email')))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_email',$language->get('registererror_email_missing'));
        }
        elseif (!preg_match($core->get('email_preg'),$core->cleaned('email')))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_email',$language->get('registererror_email_regex'));
        }
        elseif ($core->cleaned('email') != $core->cleaned('email2'))
        {
            $registererror = TRUE;
            $template->set('register','lang_registererror_email2',$language->get('registererror_email_equal'));
        }
        else
        {
            $template->set('register','lang_registererror_email','');
            $template->set('register','lang_registererror_email2','');
        }


        $query = 'SELECT
                    customuserfield.customuserfieldid AS customuserfieldid,
                    customuserfield.name AS name,
                    customuserfield.fieldtype AS fieldtype,
                    customuserfield.field AS field,
                    customuserfield.description AS description,
                    customuserfield.required AS required
                  FROM `'.TABLEPREFIX.'customuserfield` AS customuserfield
                  ORDER BY customuserfield.required DESC';
        $core->db->prepare($query);
        $core->db->execute();
        $array = $core->db->fetchAll();
        $core->db->free();

        $requiredfields = '';
        $fields = '';
        $registererror = $core->generateCustomfields($array,'customuserfieldid',$requiredfields,$fields,$fieldvalue);

        if (!$registererror)
        {
            $pass = $core->createPassword($core->cleaned('password'));
            $query = 'INSERT INTO `'.TABLEPREFIX.'user`
                      (
                        usergroupid,
                        username,
                        password,
                        salt,
                        email,
                        active
                      )
	                  VALUES
	                  (
	                    :usergroupid,
	                    :username,
	                    :password,
	                    :salt,
	                    :email,
	                    '.intval((bool)$core->get('activation_needed')).'
	                  )';
            $core->db->prepare($query);
            $core->db->bind('usergroupid',($core->get('validation_required') ? 4 : 3),Database::PARAM_INT);
            $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
            $core->db->bind('password',$pass['password'],Database::PARAM_STR);
            $core->db->bind('salt',$pass['salt'],Database::PARAM_STR);
            $core->db->bind('email',$core->cleaned('email'),Database::PARAM_STR);
            $core->db->execute();
            $core->db->free();
            $lastinsertid = $core->db->lastInsertId();
            $core->db->free();
            unset($query);
             
             
            $query = 'INSERT INTO `'.TABLEPREFIX.'customuserfieldvalue`
	                  (
	                    customuserfieldid,
	                    userid,
	                    value
	                  )
	                  VALUES
	                  ';
            $i = 1;
            $subquery = array();
            foreach ($fieldvalue as $key => $value)
            {
                $subquery[] = '(:customuserfieldid_'.$i.',:userid_'.$i.',:value_'.$i.')';
                $i++;
            }
             
            $core->db->prepare($query.implode(',',$subquery));
            $i = 1;
            foreach ($fieldvalue as $key => $value)
            {
                $core->db->bind('customuserfieldid_'.$i,$key,Database::PARAM_INT);
                $core->db->bind('userid_'.$i,$lastinsertid,Database::PARAM_INT);
                $core->db->bind('value_'.$i,serialize($value),Database::PARAM_STR);
                $i++;
            }
            unset($i,$query,$subquery,$key,$value,$fieldvalue);
            $core->db->execute();
            $core->db->free();
            $query = 'INSERT INTO `'.TABLEPREFIX.'datastorage`
	                  (
	                  	name,
	                  	identifier,
	                  	value
	                  )
	                  VALUES
	                  (
	                    "activationcode",
	                    :identifier,
	                    :value
	                  )';
            $randarray = range('!','~');
            shuffle($randarray);
            $activationcode = substr(md5(implode('',$randarray)),0,10);
            $core->db->prepare($query);
            $core->db->bind('identifier',$lastinsertid,Database::PARAM_INT);
            $core->db->bind('value',serialize($activationcode),Database::PARAM_STR);
            $core->db->execute();
            $core->db->free();
             

            if ($core->get('activation_needed'))
            {
                $message = sprintf($language->get('registration_successful_activate'),$core->get('name'));
                $url = $session->generateURL('register.php',array('do' => 'activate','username' => $core->cleaned('username'),'activationcode' => $activationcode));
                $subject = sprintf($language->get('activationmail_subject'),$core->get('name'));
                $body = sprintf($language->get('activationmail_body'),$core->cleaned('username'),$core->get('pagetitle'),$url);
                mail($core->cleaned('email'),$subject,$body,$core->get('activationmail_header'));
                unset($url,$subject,$body);
            }
            else
            {
                $message = $language->get('registration_successful_noactivate');
            }
            $template->set('redirect','url',$session->generateURL('index.php'));
            $template->set('redirect','lang_redirect',$language->get('redirect'));
            $template->set('redirect','message',$language->get('registration_successful').$message);
             
            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('redirect'));
            $template->out('home');
        }
        else
        {
            $template->set('register','lang_username',$language->get('username'));
            $template->set('register','lang_password',$language->get('password'));
            $template->set('register','lang_password_repeat',$language->get('password_repeat'));
            $template->set('register','lang_email_repeat',$language->get('email_repeat'));
            $template->set('register','lang_email',$language->get('email'));
            $template->set('register','lang_register',$language->get('register'));
            $template->set('register','lang_mandatoryfield',$language->get('mandatoryfield'));
            $template->set('register','lang_mandatoryfielddescription',$language->get('mandatoryfielddescription'));
            $template->set('register','lang_optionalfield',$language->get('optionalfield'));
            $template->set('register','lang_optionalfielddescription',$language->get('optionalfielddescription'));
            $template->set('register','request_username',$core->cleaned('username'));
            $template->set('register','request_email',$core->cleaned('email'));
            $template->set('register','request_email2',$core->cleaned('email2'));
            $template->set('register','requiredcustomfield',$requiredfields);
            $template->set('register','customfield',$fields);
             
            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('register'));
            $template->out('home');
        }
    }
    else
    {
        $query = 'SELECT
                    customuserfield.customuserfieldid AS customuserfieldid,
                    customuserfield.name AS name,
                    customuserfield.fieldtype AS fieldtype,
                    customuserfield.field AS field,
                    customuserfield.description AS description,
                    customuserfield.required AS required
                  FROM `'.TABLEPREFIX.'customuserfield` AS customuserfield
                  ORDER BY customuserfield.required DESC';
        $core->db->prepare($query);
        $core->db->execute();
        $array = $core->db->fetchAll();
        $core->db->free();

        $requiredfields = '';
        $fields = '';
        $registererror = $core->generateCustomfields($array,'customuserfieldid',$requiredfields,$fields,$fieldvalue);

        $template->set('register','lang_username',$language->get('username'));
        $template->set('register','lang_password',$language->get('password'));
        $template->set('register','lang_password_repeat',$language->get('password_repeat'));
        $template->set('register','lang_email_repeat',$language->get('email_repeat'));
        $template->set('register','lang_email',$language->get('email'));
        $template->set('register','lang_register',$language->get('register'));
        $template->set('register','lang_mandatoryfield',$language->get('mandatoryfield'));
        $template->set('register','lang_mandatoryfielddescription',$language->get('mandatoryfielddescription'));
        $template->set('register','lang_optionalfield',$language->get('optionalfield'));
        $template->set('register','lang_optionalfielddescription',$language->get('optionalfielddescription'));
        $template->set('register','lang_registererror_username','');
        $template->set('register','lang_registererror_email','');
        $template->set('register','lang_registererror_password','');
        $template->set('register','lang_registererror_email2','');
        $template->set('register','lang_registererror_password2','');
        $template->set('register','request_username','');
        $template->set('register','request_email','');
        $template->set('register','request_email2','');
        $template->set('register','requiredcustomfield',$requiredfields);
        $template->set('register','customfield',$fields);

        $template->set('home','setting_lang',$language->info('shortname'));
        $template->set('home','pagetitle',$core->get('pagetitle'));
        $template->set('home','content',$template->get('register'));
        $template->out('home');
    }
}






/*
 * Aktivierung des Accounts
 */
if ($_REQUEST['do'] == 'activate')
{
    $template_array = array('home','activate','redirect');
    $template = new Template($template_array);
    $core->clean(array('username','activationcode'),'REQUEST');
    if ($core->cleaned('username') && $core->cleaned('activationcode'))
    {
        $query = 'SELECT
                    user.userid,
                    user.active,
                    datastorage.value
                  FROM `'.TABLEPREFIX.'user` AS user
                  LEFT JOIN `'.TABLEPREFIX.'datastorage` AS datastorage ON (datastorage.name="activationcode" AND datastorage.identifier=user.userid)
                  WHERE user.username=:username
                  LIMIT 1';
        $core->db->prepare($query);
        $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
        $core->db->execute();
        $array = $core->db->fetchAll();
        $core->db->free();

        $activationerror = FALSE;
        if (!strlen($array[0]['userid']))
        {
            $activationerror = TRUE;
            $template->set('activate','lang_activationerror_username',$language->get('activationerror_username_does_not_exist'));
        }
        elseif ($array[0]['active'])
        {
            $activationerror = TRUE;
            $template->set('activate','lang_activationerror_username',$language->get('activationerror_username_active'));
        }
        else
        {
            $template->set('activate','lang_activationerror_username','');
        }


        if (unserialize($array[0]['value']) != $core->cleaned('activationcode') && !$activationerror)
        {
            $activationerror = TRUE;
            $template->set('activate','lang_activationerror_activationcode',$language->get('activationerror_activationcode_wrong_code'));
        }
        else
        {
            $template->set('activate','lang_activationerror_activationcode','');
        }


        if ($activationerror)
        {
            $template->set('activate','lang_username',$language->get('username'));
            $template->set('activate','lang_activationcode',$language->get('activationcode'));
            $template->set('activate','lang_activate',$language->get('activate'));
            $template->set('activate','request_username',$core->html($core->cleaned('username')));
            $template->set('activate','request_activationcode',$core->html($core->cleaned('activationcode')));
             
            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('activate'));
            $template->out('home');
        }
        else
        {
            $query = 'UPDATE `'.TABLPREFIX.'user` AS user
                      SET
                        user.active=1
                      WHERE user.userid=:userid';
            $core->db->prepare($query);
            $core->db->bind('userid',$array[0]['userid'],Database::PARAM_INT);
            $core->db->execute();
            $core->db->free();

            $query = 'DELETE
                        datastorage.*
                      FROM `'.TABLEPREFIX.'datastorage` AS datastorage
                      WHERE datastorage.name="activationcode"
                        AND datastorage.identifier=:userid';
            $core->db->prepare($query);
            $core->db->bind('userid',$array[0]['userid'],Database::PARAM_INT);
            $core->db->execute();
            $core->db->free();

            $template->set('redirect','url',$session->generateURL('index.php'));
            $template->set('redirect','lang_redirect',$language->get('redirect'));
            $template->set('redirect','message',$language->get('activation_successful'));

            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('redirect'));
            $template->out('home');
        }
    }
    else
    {
        if ($core->cleaned('username'))
        {
            $template->set('activate','lang_activationerror_activationcode',$language->get('activationerror_activationcode_missing'));
        }
        else
        {
            $template->set('activate','lang_activationerror_activationcode','');
        }

        if ($core->cleaned('activationcode'))
        {
            $template->set('activate','lang_activationerror_username',$language->get('activationerror_username_missing'));
        }
        else
        {
            $template->set('activate','lang_activationerror_username','');
        }

        $template->set('activate','lang_username',$language->get('username'));
        $template->set('activate','lang_activationcode',$language->get('activationcode'));
        $template->set('activate','lang_activate',$language->get('activate'));
        $template->set('activate','request_username',$core->html($core->cleaned('username')));
        $template->set('activate','request_activationcode',$core->html($core->cleaned('activationcode')));

        $template->set('home','setting_lang',$language->info('shortname'));
        $template->set('home','pagetitle',$core->get('pagetitle'));
        $template->set('home','content',$template->get('activate'));
        $template->out('home');
    }
}





/*
 * Neue Aktivierungsmail anfordern
 */
if ($_REQUEST['do'] == 'activationmail')
{
    $template_array = array('home','activationmail','redirect');
    $template = new Template($template_array);
    $core->clean(array('username','email'),'POST');
    if ($_POST['submit'])
    {
        $activationmailerror = FALSE;
        if (!strlen($core->cleaned('username')))
        {
            $activationmailerror = TRUE;
            $template->set('activationmail','lang_activationmailerror_username',$language->get('activationmailerror_username_missing'));
        }
        else
        {
            $template->set('activationmail','lang_activationmailerror_username','');
        }

        if (!strlen($core->cleaned('email')))
        {
            $activationmailerror = TRUE;
            $template->set('activationmail','lang_activationmailerror_email',$language->get('activationmailerror_email_missing'));
        }
        else
        {
            $template->set('activationmail','lang_activationmailerror_email','');
        }

        if (!$activationmailerror)
        {
            $query = 'SELECT
                        user.userid,
                        user.active
                      FROM `'.TABLEPREFIX.'user` AS user
                      WHERE user.username=:username
                        AND user.email=:email
                      LIMIT 1';
            $core->db->prepare($query);
            $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
            $core->db->bind('email',$core->cleaned('email'),Database::PARAM_STR);
            $core->db->execute();
            $array = $core->db->fetchAll();
            $core->db->free();

            if (!$array[0]['userid'])
            {
                $activationmailerror = TRUE;
                $template->set('activationmail','lang_activationmailerror_username',$language->get('activationmailerror_username_not_found'));
            }
            elseif (!$array[0]['active'])
            {
                $activationmailerror = TRUE;
                $template->set('activationmail','lang_activationmailerror_username',$language->get('activationmailerror_username_active'));
            }
            else
            {
                $template->set('activationmail','lang_activationmailerror_username','');
            }
        }


        if ($activationmailerror)
        {
            $template->set('activationmail','lang_username',$language->get('username'));
            $template->set('activationmail','lang_email',$language->get('email'));
            $template->set('activationmail','lang_requestactivationmail',$language->get('requestactivationmail'));
            $template->set('activationmail','request_username',$core->cleaned('username'));
            $template->set('activationmail','request_email',$core->cleaned('email'));

            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('activationmail'));
            $template->out('home');
        }
        else
        {
            $query = 'REPLACE INTO `'.TABLEPREFIX.'datastorage`
	                  (
	                  	name,
	                  	identifier,
	                  	value
	                  )
	                  VALUES
	                  (
	                    "activationcode",
	                    :identifier,
	                    :value
	                  )';
            $activationcode = substr(md5(implode('',$randarray)),0,10);
            $core->db->prepare($query);
            $core->db->bind('identifier',$array[0]['userid'],Database::PARAM_INT);
            $core->db->bind('value',serialize($activationcode),Database::PARAM_STR);
            $core->db->execute();
            $core->db->free();

            $url = $session->generateURL('register.php',array('do' => 'activate','username' => $core->cleaned('username'),'activationcode' => $activationcode));
            $subject = sprintf($language->get('activationmail_subject'),$core->get('name'));
            $body = sprintf($language->get('activationmail_body'),$core->cleaned('username'),$core->get('pagetitle'),$url);
            mail($core->cleaned('email'),$subject,$body,$core->get('activationmail_header'));
            unset($url,$subject,$body);
             
            $template->set('redirect','url',$session->generateURL('index.php'));
            $template->set('redirect','lang_redirect',$language->get('redirect'));
            $template->set('redirect','message',$language->get('activationmail_successful'));

            $template->set('home','setting_lang',$language->get('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('redirect'));
            $template->out('home');
        }
    }
    else
    {
        $template->set('activationmail','lang_username',$language->get('username'));
        $template->set('activationmail','lang_email',$language->get('email'));
        $template->set('activationmail','lang_requestactivationmail',$language->get('requestactivationmail'));
        $template->set('activationmail','request_username',$core->cleaned('username'));
        $template->set('activationmail','request_email',$core->cleaned('email'));

        $template->set('home','setting_lang',$language->info('shortname'));
        $template->set('home','pagetitle',$core->get('pagetitle'));
        $template->set('home','content',$template->get('activationmail'));
        $template->out('home');
    }
}





/*
 * Neues Passwort setzen
 */
if ($_REQUEST['newpassword'])
{
    $template_array = array('home','newpassword','redirect');
    $template = new Template($template_array);
    $core->clean(array('username','email','oldpassword'),'REQUEST');
    $core->clean(array('password','password2'),'POST');
    if ($_POST['submit'])
    {
        $query = 'SELECT
                    user.userid,
                    datastorage1.value AS newpassword
                  FROM `'.TABLEPREFIX.'user` AS user
                  LEFT JOIN `'.TABLEPREFIX.'datastorage` AS datastorage1 ON (datastorage1.name="newpassword" AND datastorage1.identifier=user.userid)
                  WHERE user.username=:username
                    AND user.email=:email
                  LIMIT 1';
        $core->db->prepare($query);
        $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
        $core->db->bind('username',$core->cleaned('username'),Database::PARAM_STR);
        $core->db->execute();
        $array = $core->db->fetchAll();
        $core->db->free();

        $newpassworderror = FALSE;
        if (!strlen($core->cleaned('username')))
        {
            $template->set('newpassword','lang_newpassworderror_username',$language->get('newpassworderror_username_missing'));
            $newpassworderror = TRUE;
        }
        elseif (!$array['userid'])
        {
            $template->set('newpassword','lang_newpassworderror_username',$language->get('newpassworderror_username_not_found'));
            $newpassworderror = TRUE;
        }
        else
        {
            $template->set('newpassword','lang_newpassworderror_username','');
        }

        if (!strlen($core->cleaned('oldpassword')))
        {
            $template->set('newpassword','lang_newpassworderror_oldpassword',$language->get('newpassworderror_oldpassword_missing'));
            $newpassworderror = TRUE;
        }
        elseif (unserialize($array[0]['newpassword']) != $core->cleaned('oldpassword'))
        {
            $template->set('newpassword','lang_newpassworderror_oldpassword',$language->get('newpassworderror_oldpassword_wrong_password'));
            $newpassworderror = TRUE;
        }
        else
        {
            $template->set('newpassword','lang_newpassworderror_oldpassword','');
        }

        if (!strlen($core->cleaned('email')))
        {
            $template->set('newpassword','lang_newpassworderror_email',$language->get('newpassworderror_email_missing'));
            $newpassworderror = TRUE;
        }
        else
        {
            $template->set('newpassword','lang_newpassworderror_email','');
        }

        if (!strlen($core->cleaned('password')))
        {
            $registererror = TRUE;
            $template->set('newpassword','lang_newpassworderror_password',$language->get('newpassworderror_password_missing'));
        }
        elseif (strlen($core->cleaned('password')) < $core->get('password_min'))
        {
            $registererror = TRUE;
            $template->set('newpassword','lang_newpassworderror_password',$language->get('newpassworderror_password_length'));
        }
        elseif ($core->cleaned('password') != $core->cleaned('password2'))
        {
            $registererror = TRUE;
            $template->set('newpassword','lang_newpassworderror_password2',$language->get('newpassworderror_password_equal'));
        }
        else
        {
            $template->set('newpassword','lang_newpassworderror_password','');
            $template->set('newpassword','lang_newpassworderror_password2','');
        }


        if (!$newpassworderror)
        {
            $query = 'UPDATE `'.TABLEPREFIX.'user` AS user
                      SET
                        user.password=:password,
                        user.salt=:salt
                      WHERE user.userid=:userid';
            $core->db->prepare($query);
            $pass = $core->createPassword($core->cleaned('password'));
            $core->db->bind('password',$pass['password'],Database::PARAM_STR);
            $core->db->bind('salt',$pass['salt'],Database::PARAM_STR);
            $core->db->bind('userid',$array[0]['userid'],Database::PARAM_INT);
            $core->db->execute();
            $core->db->free();

            $template->set('redirect','url',$session->generateURL('login.php'));
            $template->set('redirect','lang_redirect',$language->get('redirect'));
            $template->set('redirect','message',$language->get('newpassword_successful'));

            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('redirect'));
            $template->out('home');
        }
        else
        {
            $template->set('newpassword','lang_username',$language->get('username'));
            $template->set('newpassword','lang_password',$language->get('password'));
            $template->set('newpassword','lang_password_repeat',$language->get('password_repeat'));
            $template->set('newpassword','lang_email',$language->get('email'));
            $template->set('newpassword','request_username',$core->cleaned('username'));
            $template->set('newpassword','request_email',$core->cleaned('email'));
            $template->set('newpassword','lang_newpassword',$language->get('newpassword'));
             
            $template->set('home','setting_lang',$language->info('shortname'));
            $template->set('home','pagetitle',$core->get('pagetitle'));
            $template->set('home','content',$template->get('newpassword'));
            $template->out('home');
        }
    }
    else
    {
        $template->set('newpassword','lang_newpassworderror_username','');
        $template->set('newpassword','lang_newpassworderror_email','');
        $template->set('newpassword','lang_newpassworderror_password','');
        $template->set('newpassword','lang_newpassworderror_password2','');
        $template->set('newpassword','lang_newpassworderror_oldpassword','');
        $template->set('newpassword','lang_username',$language->get('username'));
        $template->set('newpassword','lang_password',$language->get('password'));
        $template->set('newpassword','lang_password_repeat',$language->get('password_repeat'));
        $template->set('newpassword','lang_email',$language->get('email'));
        $template->set('newpassword','request_username',$core->cleaned('username'));
        $template->set('newpassword','request_email',$core->cleaned('email'));
        $template->set('newpassword','lang_newpassword',$language->get('newpassword'));

        $template->set('home','setting_lang',$language->info('shortname'));
        $template->set('home','pagetitle',$core->get('pagetitle'));
        $template->set('home','content',$template->get('newpassword'));
        $template->out('home');
    }
}
?>